package exportimporterentities;

import java.util.ArrayList;

import api.entitites.IGarage;
import api.entitites.IMaster;
import api.entitites.IOrder;
import api.exportimportentities.IExportImportEntities;
import api.messages.Messager;

public class ExportImportEntities implements IExportImportEntities {

	private ArrayList<String> arrayMessanger = new ArrayList<String>();
	

	private Export exporter = new Export();
	private Import importer = new Import();

	public ArrayList<String> ExportGarages(ArrayList<IGarage> garList) {
		arrayMessanger.clear();
		try {
			exporter.exportGarage(garList);
			arrayMessanger.add(Messager.EXPORT);
		} catch (RuntimeException e) {
			arrayMessanger.add(e.getMessage());
		}
		return arrayMessanger;
	}

	public ArrayList<String> ExportMasters(ArrayList<IMaster> masList) {
		arrayMessanger.clear();
		try {
			exporter.exportMaster(masList);
			arrayMessanger.add(Messager.EXPORT);
		} catch (RuntimeException e) {
			arrayMessanger.add(e.getMessage());
		}
		return arrayMessanger;
	}

	public ArrayList<String> ExportOrders(ArrayList<IOrder> ordList) {
		arrayMessanger.clear();
		try {
			exporter.exportOrder(ordList);
			arrayMessanger.add(Messager.EXPORT);
		} catch (RuntimeException e) {
			arrayMessanger.add(e.getMessage());
		}
		
		return arrayMessanger;

	}

	public ArrayList<String> ImportGarages(ArrayList<IGarage> garList) {
		arrayMessanger.clear();
		try {
			if (!garList.isEmpty()) {
				garList.clear();
			}
			garList.addAll(importer.getGarages());
			arrayMessanger.add(Messager.IMPORT);
		} catch (RuntimeException e) {
			arrayMessanger.add(e.getMessage());
		}
		return arrayMessanger;
	}

	public ArrayList<String> ImportMasters(ArrayList<IMaster> masList) {
		arrayMessanger.clear();
		try {
			if (!masList.isEmpty()) {

				masList.clear();
			}
			masList.addAll(importer.getMasters());
			arrayMessanger.add(Messager.IMPORT);
		} catch (RuntimeException e) {
			arrayMessanger.add(e.getMessage());
		}
		return arrayMessanger;
	}

	public ArrayList<String> ImportOrders(ArrayList<IOrder> ordList) {
		arrayMessanger.clear();
		try {
			if (!ordList.isEmpty()) {
				ordList.clear();
			}
			ordList.addAll(importer.getOrders());
			arrayMessanger.add(Messager.IMPORT);
		} catch (RuntimeException e) {
			arrayMessanger.add(e.getMessage());
		}
		return arrayMessanger;
	}

}
